﻿///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Interface of event container 
///</describe>
/// <date>2019/7/16</date>
///***********************************************************************
#ifndef IEVENTHANDLER_H
#define IEVENTHANDLER_H

#include <functional>
#include <memory>
#include "EventArgs.h"

struct EventPara
{
    // Sender
    void* pSender;

    // Receiver
    void* pReceiver;

    // Event id
    int iEventID;

    // Event args
    SystemTool::EventArgs* pArgs;

    EventPara()
    {
        pSender=NULL;

        pReceiver=NULL;

        iEventID=-1;

        pArgs=NULL;
    }
};

class IEventHandler
{
public:
	typedef std::function<void(EventPara&)> HandlerFunc;
    typedef std::shared_ptr<HandlerFunc> ProcessFunc;

public:
    // Destruct the event handler
    virtual ~IEventHandler(){    }

public:
    // Fire event
    virtual void FireEvent(void* pSender,int iEventID, SystemTool::EventArgs* pArgs)=0;

    // Register an object's callback to the event handler
    virtual bool RegisterEvent(void* pReceiver, int iEventID, ProcessFunc pHandlerFunc)=0;

    // UnRegister receiver
    virtual bool UnRegisterEvent(void* pReceiver)=0;

    // UnRegister receiver
    virtual bool UnRegisterEvent(void* pReceiver, int iEventID)=0;

    // UnRegister an object's callback from the event handler
    virtual bool UnRegisterEvent(void* pReceiver, int iEventID, ProcessFunc pHandlerFunc)=0;

    // UnRegister all eventids
    virtual bool UnRegisterEvent(int iEventID)=0;

    // UnRegister all eventid's func
    virtual bool UnRegisterEvent(int iEventID, ProcessFunc pHandlerFunc)=0;

    // UnRegister all funcs
    virtual bool UnRegisterEvent(ProcessFunc pHandlerFunc)=0;
};

#endif //EVENTHANDLER_H
